// const getUrl = "http://lgd.365linghuo.cn"; // 请求地址
const getUrl = "http://lgd.linggongda.cn"; // 请求地址
function getData(url, method, data, cb,loadText) { // 请求数据方法
	console.log(data)
  uni.request({
    // url: getUrl + url + "?app_id=10001&source=wx&token="+wx.getStorageSync('token'),
    url: getUrl + url,
    data: data,
    method: method,
    header: {
      'Authorization': 'Bearer' + " " + uni.getStorageSync('token'),
      'Content-Type': 'application/json',
    },
    success: function(res) {
      if(res.data.code != 200 && url != '/api/member/message_log'){
		  if(res.data.message != '未授权'){
				uni.showToast({
				  title: res.data.message,
				  icon: 'none',
				  duration: 2000
				});
		  }
        if(res.data.code == 401){
			uni.clearStorageSync()
			// setTimeout(() => {
			//   uni.reLaunch({
			// 	url: '/pages/index/index',
			//   })
			// }, 2000)
        }
        if(res.data.message == '您还未认证, 请先认证再报名'){
			setTimeout(() => {
			  uni.navigateTo({
				url: '/pages/certification/certification',
			  })
			}, 2000)
        }
      }
      return typeof cb == "function" && cb(res.data)
    },
    fail: function(res) {
      uni.hideLoading();
      return typeof cb == "function" && cb(false)
    }
  })
}

module.exports = {
  getData: getData,
  getUrl: getUrl
}
